package com.niit.onlinemusic.controller;

import com.niit.onlinemusic.common.R;
import com.niit.onlinemusic.service.SongService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 歌曲控制器
 *
 * @author zuwei522
 * @since 2025/9/19 08:31
 */
@Slf4j
@RestController
@RequestMapping("song")
public class SongController {

    private final SongService songService;

    public SongController(SongService songService) {
        this.songService = songService;
    }

    /**
     * 根据歌手ID查询歌曲
     *
     * @param singerId 歌手ID
     * @return 歌曲列表
     * @author zuwei522
     * @since 2025/9/19 08:41
     */
    @GetMapping("singer/detail")
    public R getSongs(@RequestParam int singerId) {
        return songService.getSongsBySingerId(singerId);
    }

    /**
     * 查询所有歌曲
     *
     * @return R
     * @author zuwei522
     * @since 2025/9/28 00:08
     */
    @GetMapping
    public R getAllSongs() {
        return R.success("查询成功", songService.list());
    }

    /**
     * 根据歌曲名字查询歌曲
     *
     * @param name 歌曲名字
     * @return R
     * @author zuwei522
     * @since 2025/9/29 14:51
     */
    @GetMapping("singerName/detail")
    public R getSongsBySingerName(@RequestParam("name") String name) {
        log.info("根据歌曲名字查询歌曲，歌曲名字：{}", name);
        return songService.searchSongsByName(name);
    }

}
